package org.edu.page;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.HashMap;
import java.util.Map;

@ApiModel(value="PageCondition", description="分页条件")
public class PageCondition
{
    @ApiModelProperty(value="当前页", name="pageIndex", required=true, example="1")
    private int pageIndex;
    @ApiModelProperty(value="每页记录数", name="pageSize", required=true, example="10")
    private int pageSize;

    public String toString()
    {
        return "PageCondition(pageIndex=" + getPageIndex() + ", pageSize=" + getPageSize() + ", filter=" + getFilter() + ", sorter=" + getSorter() + ")";
    }

    public int hashCode()
    {
        int PRIME = 59;int result = 1;result = result * 59 + getPageIndex();result = result * 59 + getPageSize();Object $filter = getFilter();result = result * 59 + ($filter == null ? 43 : $filter.hashCode());Object $sorter = getSorter();result = result * 59 + ($sorter == null ? 43 : $sorter.hashCode());return result;
    }

    protected boolean canEqual(Object other)
    {
        return other instanceof PageCondition;
    }

    public boolean equals(Object o)
    {
        if (o == this) {
            return true;
        }
        if (!(o instanceof PageCondition)) {
            return false;
        }
        PageCondition other = (PageCondition)o;
        if (!other.canEqual(this)) {
            return false;
        }
        if (getPageIndex() != other.getPageIndex()) {
            return false;
        }
        if (getPageSize() != other.getPageSize()) {
            return false;
        }
        Object this$filter = getFilter();Object other$filter = other.getFilter();
        if (this$filter == null ? other$filter != null : !this$filter.equals(other$filter)) {
            return false;
        }
        Object this$sorter = getSorter();Object other$sorter = other.getSorter();return this$sorter == null ? other$sorter == null : this$sorter.equals(other$sorter);
    }

    public void setSorter(String sorter)
    {
        this.sorter = sorter;
    }

    public void setFilter(Map<String, Object> filter)
    {
        this.filter = filter;
    }

    public void setPageSize(int pageSize)
    {
        this.pageSize = pageSize;
    }

    public void setPageIndex(int pageIndex)
    {
        this.pageIndex = pageIndex;
    }

    public PageCondition(int pageIndex, int pageSize, Map<String, Object> filter, String sorter)
    {
        this.pageIndex = pageIndex;this.pageSize = pageSize;this.filter = filter;this.sorter = sorter;
    }

    public int getPageIndex()
    {
        return this.pageIndex;
    }

    public int getPageSize()
    {
        return this.pageSize;
    }

    @ApiModelProperty(value="过滤条件", name="filter", required=true)
    private Map<String, Object> filter = new HashMap();
    @ApiModelProperty(value="排序条件", name="sorter", example="name DESC")
    private String sorter;

    public Map<String, Object> getFilter()
    {
        return this.filter;
    }

    public String getSorter()
    {
        return this.sorter;
    }

    public PageCondition(Map map)
    {
        this.pageSize = 10;
        this.pageIndex = 1;
        this.filter.putAll(map);
    }

    public PageCondition(int pageIndex, int pageSize, String sorter)
    {
        this.pageIndex = (pageIndex - 1);
        this.pageSize = pageSize(pageSize);
        this.sorter = sorter;
    }

    public PageCondition(int pageIndex, int pageSize)
    {
        this.pageIndex = (pageIndex - 1);
        this.pageSize = pageSize(pageSize);
    }

    public Object getFilterValue(String key)
    {
        if (null != this.filter) {
            return this.filter.get(key);
        }
        return null;
    }

    private int pageSize(int pageSize)
    {
        if (pageSize == 0) {
            return 9999;
        }
        return pageSize;
    }

    public PageCondition() {}
}
